package com.example.carproviderbackstage.service.impl.dl.admin;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.carinterface.service.dl.admin.InsuranceService;
import com.example.carinterface.utils.ResultJson;
import com.example.carproviderbackstage.mapper.dl.admin.InsuranceMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InsuranceServiceImpl implements InsuranceService {

    @Autowired
    private ResultJson<List<Map<String, Object>>> mapListResultJson;
    @Autowired
    private InsuranceMapper insuranceMapper;

    @Override
    public ResultJson<List<Map<String, Object>>> findAllInsuranceOrder(Map<String, Object> map) {

        if (map==null){
            map = new HashMap<>();
        }

        //查询基本信息
        List<Map<String, Object>> maps = insuranceMapper.findBaseInsuranceOrder(map);
        if (map.get("id") != null&&maps.size()==1) {
            //查询细节
            List<Map<String, Object>> details = insuranceMapper.findDetailsInsuranceOrder(map);
            Map<String, Object> stringObjectMap = maps.get(0);
            stringObjectMap.put("details", details);
            maps.set(0, stringObjectMap);
        }
        mapListResultJson.setSuccess("查询保险订单成功", maps);
        return mapListResultJson;
    }

    @Override
    public ResultJson<String> addInsuranceOrder(Map<String, Object> map) {

        //

        //









        return null;
    }

    @Override
    public ResultJson<String> updateInsuranceState(Map<String, Object> map) {
        ResultJson<String> stringResultJson = new ResultJson<>();
        int i = insuranceMapper.updateInsuranceState(map);

        if (i==1){
            stringResultJson.setSuccess("审核通过");
        }else {
            stringResultJson.setSuccess("审核失败");
        }
        return stringResultJson;
    }
}
